//! Basic HTTP Protocol Test
//! 
//! This example tests basic HTTP protocol functionality without external dependencies.

use ai_test_platform::protocols::{http::HttpProtocolHandler, ProtocolHandler};
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== Basic HTTP Protocol Test ===");
    
    // Create HTTP protocol handler
    let mut handler = HttpProtocolHandler::new();
    println!("✓ HTTP protocol handler created");
    
    // Test protocol name
    assert_eq!(handler.protocol_name(), "http");
    println!("✓ Protocol name: {}", handler.protocol_name());
    
    // Test supported operations
    let operations = handler.supported_operations();
    println!("✓ Supported operations: {:?}", operations);
    assert!(operations.contains(&"get".to_string()));
    assert!(operations.contains(&"post".to_string()));
    assert!(operations.contains(&"put".to_string()));
    assert!(operations.contains(&"delete".to_string()));
    assert!(operations.contains(&"patch".to_string()));
    assert!(operations.contains(&"head".to_string()));
    assert!(operations.contains(&"options".to_string()));
    
    // Initialize with basic configuration
    let config = HashMap::new();
    handler.initialize(config).await?;
    println!("✓ HTTP protocol handler initialized");
    
    // Test parameter validation
    println!("\n=== Testing Parameter Validation ===");
    
    let mut valid_params = HashMap::new();
    valid_params.insert("url".to_string(), serde_json::json!("https://example.com"));
    
    match handler.validate_params("get", &valid_params) {
        Ok(_) => println!("✓ Valid HTTPS parameters accepted"),
        Err(e) => {
            println!("✗ Valid HTTPS parameters rejected: {}", e);
            return Err(e.into());
        }
    }
    
    let mut http_params = HashMap::new();
    http_params.insert("url".to_string(), serde_json::json!("http://example.com"));
    
    match handler.validate_params("get", &http_params) {
        Ok(_) => println!("✓ Valid HTTP parameters accepted"),
        Err(e) => {
            println!("✗ Valid HTTP parameters rejected: {}", e);
            return Err(e.into());
        }
    }
    
    // Test invalid parameters
    let empty_params = HashMap::new();
    match handler.validate_params("get", &empty_params) {
        Ok(_) => println!("⚠ Empty parameters unexpectedly accepted"),
        Err(_) => println!("✓ Empty parameters correctly rejected"),
    }
    
    let mut invalid_scheme_params = HashMap::new();
    invalid_scheme_params.insert("url".to_string(), serde_json::json!("ftp://example.com"));
    
    match handler.validate_params("get", &invalid_scheme_params) {
        Ok(_) => println!("⚠ Invalid scheme parameters unexpectedly accepted"),
        Err(_) => println!("✓ Invalid scheme parameters correctly rejected"),
    }
    
    // Test unsupported operation
    println!("\n=== Testing Unsupported Operation ===");
    
    let test_params = HashMap::new();
    let mut context = ai_test_platform::models::step::StepContext::new(
        uuid::Uuid::new_v4(), 
        uuid::Uuid::new_v4()
    );
    
    match handler.execute("unsupported_operation", test_params, &mut context).await {
        Ok(_) => println!("⚠ Unsupported operation unexpectedly succeeded"),
        Err(_) => println!("✓ Unsupported operation correctly rejected"),
    }
    
    println!("\n=== Basic Test Completed Successfully ===");
    println!("HTTP protocol handler basic functionality is working correctly!");
    println!("- Protocol name: ✓");
    println!("- Supported operations: ✓");
    println!("- Initialization: ✓");
    println!("- Parameter validation: ✓");
    println!("- Error handling: ✓");
    
    Ok(())
}
